/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/




#if !defined(AFX_PGLLEGEND_H__D9B6DFE3_F601_4CCC_B09A_518A7AE5CAE4__INCLUDED_)
#define AFX_PGLLEGEND_H__D9B6DFE3_F601_4CCC_B09A_518A7AE5CAE4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLObjectManager.h>
#include <pgl/core/PGLPave.h>

/*!  CUINTList
A list of unsigned int
*/
typedef std::list<UINT> CUINTList;

/*! \brief A legend

	\ingroup PGLRegionGroup
*/
class PGLCORE_EXT_CLASS CPGLLegend : public CPGLPave  
{
PGL_DECLARE_DYNCREATE(CPGLLegend);
public:
	//! \name Constructors
	//@{
	//! Default constructor
	CPGLLegend();
	//! Copy construtor
	CPGLLegend(const CPGLLegend& lg) {*this = lg;};
	//! Assignement construtor
	CPGLLegend& operator=(const CPGLLegend& lg);
	virtual ~CPGLLegend();
	//@}

	//! \name Object list manipulation
	//@{
	//! Add legend element on top.
	void PushTop(CPGLObjectPtr pObject);
	//! Add legend element at bottom.
	void PushBottom(CPGLObjectPtr pObject);
	//! Returns forward iterator pointing to first element
	CUINTList::iterator GetBegin()				{	return m_lIDs.begin();};
	//! Returns const forward iterator pointing to first element
	CUINTList::const_iterator GetBegin() const	{	return m_lIDs.begin();};
	//! Returns forward iterator pointing to last element
	CUINTList::iterator GetEnd()				{	return m_lIDs.end();};
	//! Returns const forward iterator pointing to last element
	CUINTList::const_iterator GetEnd() const	{	return m_lIDs.end();};
	//! Removes all reference in legend
	void Clear()	{	m_lIDs.clear();};
	//@}

	//! \name Positioning helpers
	//@{
	//! Enumeration describing predefined legend position.
	enum ELegendPos 
	{	
		//! place legend at lower left
		LegendPosLowerLeft=0,
		//! place legend at upper left
		LegendPosUpperLeft=1,
		//! place legend at lower right
		LegendPosLowerRight=2,
		//! place legend at upper right
		LegendPosUpperRight=3
	};

	//! Place legend to predefined positions
	void SetPosition( ELegendPos pos );
	//@}

	//! \name Resizing methods
	//@{
	//! Scales legend to fit text and drawings
	void FitBox(gfxinterface::CGfxInterface& gfx);
	//@}
	
	//!\name Getters
	//@{
	//! returns text object controlling the style
	CPGLText& GetTextStyle()				{	return m_text;};
	//! returns text object controlling the style, const
	const CPGLText& GetTextStyle() const	{	return m_text;};
	//@}
	//! \name Virutal plotting functions
	//@{
	//! Main plot function
	virtual void PlotGfx(gfxinterface::CGfxInterface& gfx);
	virtual void GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent) {	CPGLPave::GetUnionExtent(gfx,rExtent); rExtent.xValid = false;	rExtent.yValid = false;};
	virtual void UpdateExtent(gfxinterface::CGfxInterface& gfx);
	//@}
	
	//! \name Serialization and debugging
	//@{
	//! Serialization
	void SerializeXML( CPGLArchive& ar);
	#ifdef _DEBUG
		//! MFC Dump
	    virtual void Dump( CDumpContext& dc ) const;
		//! MFC AssertValid
	    virtual void AssertValid() const;    // Override
	#endif
	//@}

protected:
	//! \name Attributes
	//@{
	//! List of object IDs
	CUINTList m_lIDs;
	//! Width (pixels) of marker 
	double m_dMarkerWidth;
	//! Text style
	CPGLText m_text;
	//@}
};

PGL_DECLARE_SMARTPTR( CPGLLegend );

#endif // !defined(AFX_PGLLEGEND_H__D9B6DFE3_F601_4CCC_B09A_518A7AE5CAE4__INCLUDED_)
